/*
find date range
get sales by category for date range

*/
//============================================================================
// Name        : ROMS_main.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : C++ project Part II for your class (121, or 112) 
//============================================================================
//
#include "std_lib_facilities.h"
#include "Simple_window.h"
#include "Graph.h"
#include "GUI.h"
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/Fl_Text_Display.H>
#include <sstream> 
#include <map>
#include <iterator>
#include <algorithm>


#include "ROMS_Menu.h"

using namespace std;
using namespace ROMS;
using namespace Graph_lib;

//types we need for a ROMS GUI interface-- a memu_bar and a place to display text and a means of attaching them to a Window.

namespace Graph_lib {
//------------------------------------------------------------------------------
	struct Window_text_display : Widget {
		Window_text_display(Point XY, int W, int H, string L, Callback cb): Widget(XY, W, H, L, cb)
		{}
		void set_buffer(string s);
		void attach(Window&);
	private:
		Fl_Text_Buffer data;
		Fl_Text_Display *ptd;

	};
	void Window_text_display::attach(Window& win)
	{
		ptd = new Fl_Text_Display(loc.x, loc.y, width, height, label.c_str());
		ptd->buffer(&data);
		pw  = (Fl_Widget*) ptd;
		pw->callback(reinterpret_cast<Fl_Callback*>(do_it), &win); // pass the window
		own = &win;
	}
	void Window_text_display::set_buffer(string s) 
	{
		data.text(s.c_str());
	}

//------------------------------------------------------------------------------
	struct Menu_bar : Widget {
		Menu_bar(Point XY, int W, int H, Callback cb): Widget(XY, W, H, "", cb)
		{}
		void menu(Fl_Menu_Item *ma);
		void attach(Window&);
	private:
		Fl_Menu_Bar *pmb;
		Fl_Menu_Item *ma;

	};
	void Menu_bar::attach(Window& win)
	{
		pmb = new Fl_Menu_Bar(loc.x, loc.y, width, height);
		pmb->menu(ma);
		pw  = (Fl_Widget*) pmb;
		pw->callback(reinterpret_cast<Fl_Callback*>(do_it), &win); // pass the window
		own = &win;
	}
	void Menu_bar::menu(Fl_Menu_Item *m) 
	{
		ma = m;
	}
}

//header declarations
void do_about_box(Window&);
void do_about_help_box(Window&); //FPW, B.3
void show_find_menu_item(Window&, ROMS_Menu&); //FPW, C - find sales for menu item
void update_recipe(Window&, ROMS_Menu&); //FPW, C - add recipe
void do_read(Window&, ROMS_Menu&, string, string, Msg_type);
void Main_Window_CB(Fl_Widget*, void*);
void Menu_Bar_CB (Fl_Widget*, void*);
void Menu_Bar_2_CB (Fl_Widget*, void*); //FPW, C - find menu item sales

//AJN C
void do_add_order_item(Window&,ROMS_Menu&);
void do_find_category_sales(Window&,ROMS_Menu&);
//global data
bool main_window_click = false;
bool menu_bar_click = false;
bool main_click_enabled = true;//used to force serialization on clicks
int window_userdata;
/*This following code written by Fransiska Putri Wina to solve C - find sales for menu item */
bool menu_click_enabled = true;
int menu_userdata;
/* end of code by FPW, C - find sales for menu item */

//SBH C
void do_add_menu_item(Window&,ROMS_Menu&);
void do_find_table_sales(Window&,ROMS_Menu&);
bool searchcontinue;
//AJN D
void do_graph_order_sales(Window&,ROMS_Menu&);
void do_graph_table_sales(Window&,ROMS_Menu&);
void do_graph_category_sales(Window&,ROMS_Menu&);

//main window menu bar
//Note: for expediancy sake, to define the menu bar below we used an FLTK type Fl_Menu_Item. 
//This makes our program  directly tied to FLTK instead of Dr. Stroustrup's interface Graph_lib.
//We don't like this, but we did it to save time, which often happens in the real world.
//A better solution is to write code to hide this in the implementation of the Graph_lib::Menu_bar, but that means adding
//changes to it and getting general agreement with Dr. Stroustrup. Subsequent testing and distribution would take time we don't have.
//An extra credit exercise is to see if you can eliminate direct references in your code to FLTK types like we have here
Fl_Menu_Item menu_bar[] = {
 {"Read", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"Recipes", 0,  (Fl_Callback*)Main_Window_CB, Address (Read_recipes_ingredients), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Orders", 0,  (Fl_Callback*)Main_Window_CB, Address (Read_orders), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Menu Items", 0,  (Fl_Callback*)Main_Window_CB, Address (Read_category_menu_items), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {"Show", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"Orders", 0,  (Fl_Callback*)Main_Window_CB, Address (Show_order), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Recipes", 0,  (Fl_Callback*)Main_Window_CB, Address (Show_recipe), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Menu Items", 0,  (Fl_Callback*)Main_Window_CB, Address (Show_menu), 0, FL_NORMAL_LABEL, 0, 14, 0},
  /* These following code written by Fransiska Putri Wina to solve B.3 */
 {"Categories", 0,  (Fl_Callback*)Main_Window_CB, Address (Show_categories), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Order Items", 0,  (Fl_Callback*)Main_Window_CB, Address (Show_order_items), 0, FL_NORMAL_LABEL, 0, 14, 0},
 /* end of code by FPW, B.3 */
 {0,0,0,0,0,0,0,0,0},
 {"Find", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"Category Sales", 0,  (Fl_Callback*)Main_Window_CB, Address (Find_category_sales), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Table Sales", 0,  (Fl_Callback*)Main_Window_CB, Address (Find_table_sales), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Menu Item Sales", 0,  (Fl_Callback*)Main_Window_CB, Address (Find_menu_item_sales), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {"Update", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"Add Order Item", 0,  (Fl_Callback*)Main_Window_CB, Address (Update_add_order_item), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Add Menu Item", 0,  (Fl_Callback*)Main_Window_CB, Address (Update_add_menu_item), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Add Recipe", 0,  (Fl_Callback*)Main_Window_CB, Address (Update_add_recipe), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 //AJN D
 {"Graph", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 //Graph_order_sales,Graph_table_sales,Graph_category_sales,
 {"Graph Order Sales", 0,  (Fl_Callback*)Main_Window_CB, Address (Graph_order_sales), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Graph Table Sales", 0,  (Fl_Callback*)Main_Window_CB, Address (Graph_table_sales), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Graph Category Sales", 0,  (Fl_Callback*)Main_Window_CB, Address (Graph_category_sales), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {"About", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"Info", 0,  (Fl_Callback*)Main_Window_CB, Address (About_info), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Help", 0,  (Fl_Callback*)Main_Window_CB, Address (About_help), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {"Exit", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"Save and exit", 0,  (Fl_Callback*)Main_Window_CB, Address (Exit_program), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {0,0,0,0,0,0,0,0,0}
};


//call back functions
void recps_cb(Address addr, Address) // callback for recipes button
{
	Main_Window_CB((Fl_Widget*) addr, Address (Tables_button));
}
void order_cb(Address addr, Address) // callback for orders button
{
	Main_Window_CB((Fl_Widget*) addr, Address (Orders_button));
}
void cat_cb(Address addr, Address) // callback for category button
{
	Main_Window_CB((Fl_Widget*) addr, Address (Categories_button));
}
void mi_cb(Address addr, Address) // callback for menu item button
{
	Main_Window_CB((Fl_Widget*) addr, Address (Menu_items_button));
}
void oi_cb(Address addr, Address) // callback for order item button
{
	Main_Window_CB((Fl_Widget*) addr, Address (Recipes_button));
}
 void display_cb(Address addr, Address) // callback for display window
{
	Main_Window_CB((Fl_Widget*) addr, Address (Display_window));
}
 void menu_bar_cb(Address addr, Address)//callback for menu bar
 {
	 Menu_Bar_CB((Fl_Widget*) addr, Address (Menu_bar_cb));
 }
 /* These following code written by Fransiska Putri Wina to Solve C - Find Sales for Menu Item */
 void find_menu_item_cb(Address addr, Address)
 {
	 Menu_Bar_2_CB((Fl_Widget*) addr, Address (find_menu_item_button));
 }
/* end of code by FPW - C - find sales for menu item */
/* These following code written by Fransiska Putri Wina to Solve C - Update Recipe */
void update_recipe_cb(Address addr, Address)//callback for update order item - DS
{
	Menu_Bar_2_CB((Fl_Widget*) addr, Address (update_recipe_button));
}
/* end of code by FPW - C - update recipe */

 //AJN C
 void add_order_item_cb(Address addr, Address)//callback for menu bar
 {
	Menu_Bar_2_CB((Fl_Widget*) addr, Address (Update_add_order_item));
	
 }
 void find_category_sales_cb(Address addr, Address)//callback for update order item - DS
{
	Menu_Bar_2_CB((Fl_Widget*) addr, Address (Find_category_sales));
}
  void add_menu_item_cb(Address addr, Address)//callback for menu bar
 {
	 Menu_Bar_2_CB((Fl_Widget*) addr, Address (Update_add_menu_item));
	 
 }
  //SBH C
  void find_tbl_slz_cb(Address addr, Address)
 {
	 Menu_Bar_2_CB((Fl_Widget*) addr, Address (find_table_sales_button));
 }
 //AJN D
 void graph_order_sales_cb(Address addr, Address)//callback for Graph Order Sales
 {
	 Menu_Bar_2_CB((Fl_Widget*) addr, Address (Graph_order_sales));
	 
 }
 void graph_table_sales_cb(Address addr, Address)//callback for Graph Table Sales
 {
	 Menu_Bar_2_CB((Fl_Widget*) addr, Address (Graph_table_sales));
	 
 }
 void graph_category_sales_cb(Address addr, Address)//callback for Graph Category Sales
 {
	 Menu_Bar_2_CB((Fl_Widget*) addr, Address (Graph_category_sales));
	 
 }



void Menu_Bar_CB (Fl_Widget*, void* ud) {
	cout << "Menu Bar Callback" << " Userdata=" << (int) ud << "\n";
	menu_bar_click = true;
}
/* These following code written by Fransiska Putri Wina to Solve C - Find Sales for Menu Item */
void Menu_Bar_2_CB (Fl_Widget*, void* ud) {
	if (menu_click_enabled) {
		cout << "Menu Bar Callback" << " Userdata=" << (int) ud << "\n";
		menu_userdata = (int) ud;
		menu_bar_click = true;
		menu_click_enabled = false; //main loop active on current click
	}
}
 /* End of code by FPW - C - find sales for menu item */
void Main_Window_CB(Fl_Widget*, void* ud) {
	if(main_click_enabled)//don't signal the window click if main loop is active
	{
		cout << "Main Window Callback" << " Userdata=" << (int) ud << "\n";
		window_userdata = (int) ud;
		main_window_click = true;
		main_click_enabled = false; //main loop active on current click
	}
}
//wait functions for callbacks to be executed
void wait_for_main_window_click() {
	while (!main_window_click) 
		Fl::wait();
	main_window_click = false;
	Fl::redraw();
}

void wait_for_menu_bar_click() {
	while (!menu_bar_click)
		Fl::wait();
	menu_bar_click = false;
	Fl::redraw();
}

//Save all files
void save(ROMS_Menu m)
{
	m.save();
	return;
}

int main()
{
	//create the main window and display it
	ROMS_Menu m;
    Window sw(600, 500, "Restaurant Order Management System");
    Button recps(Point(40, 50), 100, 30, "Recipes", recps_cb);
	sw.attach(recps);
	Button order(Point(40, 100), 100, 30, "Orders", order_cb);
	sw.attach(order);
	Button cat(Point(40, 150), 100, 30, "Categories", cat_cb);
	sw.attach(cat);
	Button mi(Point(40, 200), 100, 30, "Menu Items", mi_cb);
	sw.attach(mi);
	Button ci(Point(40, 250), 100, 30, "Order Items", oi_cb);
	sw.attach(ci);
    sw.callback((Fl_Callback*)Main_Window_CB, Address (Exit_program));
	Menu_bar mb(Point(0, 0), 600, 30, menu_bar_cb);
    mb.menu(menu_bar);
	sw.attach(mb);

	Window_text_display t(Point(150,50),400, 400, "Data Display", display_cb );
	t.set_buffer("No Data Loaded\n");
	sw.attach(t);
 	sw.resizable(&sw);
	

	//main loop to execute user clicks on the main window
	//do you understand how this loop works compared to the way the main loop worked in Part I of the project?
	try {
		
		while(true) {
			main_click_enabled = true;
			wait_for_main_window_click();
			cout << "Act on userdata = " << window_userdata << endl;
			try{
			switch(window_userdata) 
			{
				//need to complete all the menu cases
				case Read_recipes_ingredients:
					do_read(sw, m, "recipes.dat", "Open Recipes/Ingredients File", Read_recipes_ingredients);
					break;
				case Read_orders:
					do_read(sw, m, "orders.dat", "Open Order/Order Items File", Read_orders);
					break;
				case Read_category_menu_items:
					do_read(sw, m, "catmenu.dat", "Open Category/Menu Item File", Read_category_menu_items);
					break;
				/* These following code written by Fransiska Putri Wina to solve B.3 */
				case Show_categories:
					t.set_buffer(m.show_menu_bar((Msg_type) window_userdata).c_str());
					break;
				case Show_order_items:
					t.set_buffer(m.show_menu_bar((Msg_type) window_userdata).c_str());
					break;
				case About_help:
					do_about_help_box(sw);
					break;
				/* end of code by FPW, B.3 */
				case Find_menu_item_sales:
					//FPW - C - Find Menu Item
					show_find_menu_item(sw,m);
					break;
				case Update_add_recipe:
					//FPW - C - update recipe
					update_recipe(sw, m);
					break;
				//SBH B.2
				case Show_menu:
					t.set_buffer(m.show_button((Msg_type) window_userdata).c_str());
					break;
				case Show_recipe:
					t.set_buffer(m.show_button((Msg_type) window_userdata).c_str());
					break;
				case Show_order:
					t.set_buffer(m.show_button((Msg_type) window_userdata).c_str());
					break;

					//SBH C
				case Find_table_sales:
					do_find_table_sales(sw,m);
					break;
				case Update_add_menu_item:
					do_add_menu_item(sw,m);
					break;

				//AJN C
				case Update_add_order_item:
					do_add_order_item(sw,m);
					break;
				case Find_category_sales:
					do_find_category_sales(sw,m);
					break;
				//AJN D
				case Graph_order_sales:
					do_graph_order_sales(sw,m);
					break;
				case Graph_table_sales:
					do_graph_table_sales(sw,m);
					break;
				case Graph_category_sales:
					do_graph_category_sales(sw,m);
					break;
 				case About_info:
					do_about_box(sw);
					break;
				case Tables_button: case Orders_button: case Categories_button: case Recipes_button: case Menu_items_button:
					t.set_buffer(m.show_button((Msg_type) window_userdata).c_str());
					break;
				case Exit_program:
					cout << "save files and exit\n";
					save(m);
					exit(0); //exit program
					break;
				default:
					cout << "case not implemented\n";
			}
			}
			catch(exception&e)
			{
				cerr<<"exception: "<<e.what()<<'\n';
			}
		}
		return 0;
	}
	catch(exception& e) {
		cerr << "exception: " << e.what() << '\n';
		return 1;
	}
	catch (...) {
		cerr << "Some exception\n";
		return 2;
	}
}

//Add Menu Item
//SBH C
void do_add_menu_item(Window& w, ROMS_Menu& m)
{
	Window add(Point(w.x()+100, w.y()+100), 400, 300, "Add Menu Item");
	add.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));
	Button save(Point(300, 200), 50, 25, "Update", add_menu_item_cb);
	add.attach(save);
	In_box recipe_id(Point(125,25),50,20,"Recipe ID:");
	In_box category_name(Point(125,50),50,20,"Category ID:");
	In_box menu_item_id(Point(125,75),50,20,"Menu Item ID:");
	In_box menu_item_name(Point(125,100),50,20,"Menu Item Name:");
	In_box price(Point(125,125),50,20,"Price:");
	In_box description(Point(125,150),350,20,"Description:");
	add.attach(recipe_id);
	add.attach(category_name);
	add.attach(menu_item_id);
	add.attach(menu_item_name);
	add.attach(price);
	add.attach(description);
	wait_for_menu_bar_click(); 
	menu_click_enabled = true;
	while (menu_userdata != Close_about_box)
	{
		cout << "Act on userdata = " << menu_userdata << endl;
		if (menu_userdata == Update_add_menu_item) { 
			int rec2= recipe_id.get_int();
			int cat2= category_name.get_int();
			int id2= menu_item_id.get_int();
			string n2= menu_item_name.get_string();
			double amt2= price.get_int();
			string s2= description.get_string();
			cout<<"Menu Item Added: "<<rec2<<" "<<cat2<<" "<<id2<<" "<<n2<<" "<<amt2<<" \n"<<s2<<endl;
			m.add_menu_item(rec2,cat2,id2,n2,amt2,s2);
		}
		wait_for_menu_bar_click(); 
		menu_click_enabled = true;
	} 

	add.detach(recipe_id);
	add.detach(category_name);
	add.detach(menu_item_id);
	add.detach(menu_item_name);
	add.detach(price);
	add.detach(description);
	return;
}

//Find Table Sales
//SBH C
void do_find_table_sales(Window& w, ROMS_Menu& m)
{
	Window add(Point(w.x()+100, w.y()+100), 350, 200, "Table Sales"); 
	add.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));

	In_box tbl_id(Point(120,10), 100, 30, "Table ID:"); 
	Text txt_result(Point(5,105), ""); 
	Button button_find(Point(67, 50), 200, 30, "Search", find_tbl_slz_cb);  

	add.attach(tbl_id); 
	add.attach(txt_result); 
	add.attach(button_find); 

	wait_for_menu_bar_click(); 
	menu_click_enabled = true;
	while (menu_userdata != Close_about_box)
	{
		cout << "Act on userdata = " << menu_userdata << endl;
		if (menu_userdata == find_table_sales_button) 
		{ 
			ostringstream oss;   
			oss << m.find(1,tbl_id.get_string()); 
			string result = oss.str(); 
			
			
			if (result == "-2") 
			{
				txt_result.set_label("Please input Table ID first");
			}
			else 
			{
				txt_result.set_label("Total sales for table " + tbl_id.get_string() + " = $" + result);	
			}
			
			
		}
		wait_for_menu_bar_click(); 
		menu_click_enabled = true;
	} 

	add.detach(tbl_id); 
	add.detach(txt_result); 
	add.detach(button_find); 
	return;

}

//Add Order Item box
//AJN C
void do_add_order_item(Window& w, ROMS_Menu& m)
{
	Window add(Point(w.x()+100, w.y()+100), 300, 150, "Add Order Item");
	add.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));
	Button save(Point(200, 100), 50, 25, "Save", add_order_item_cb);
	
	add.attach(save);
	In_box seat(Point(125,25),20,20,"Seat:");
	In_box oid(Point(125,50),50,20,"Order ID:");
	In_box miid(Point(125,75),50,20,"Menu Item ID:");
	In_box num(Point(125,100),20,20,"Number of Items:");
	add.attach(seat);
	add.attach(oid);
	add.attach(miid);
	add.attach(num);
	wait_for_menu_bar_click(); 
	menu_click_enabled = true;
	while (menu_userdata != Close_about_box)
	{
		cout << "Act on userdata = " << menu_userdata << endl;
		if (menu_userdata == Update_add_order_item) { 
			string st = seat.get_string();
			int orid = oid.get_int();
			int mitid = miid.get_int();
			int numi = num.get_int();
			cout<<"Order Item Added:  "<<st<<" "<<orid<<" "<<mitid<<" "<<numi<<endl;
			m.add_order_item(st,orid,mitid,numi);
		}
		wait_for_menu_bar_click(); 
		menu_click_enabled = true;
	} 
	add.detach(seat);
	add.detach(oid);
	add.detach(miid);
	add.detach(num);
	
	return;
}
//Find Category Sales  AJN C
void do_find_category_sales(Window& w,ROMS_Menu& m)
{
	cout<<"do find category sales"<<endl;
	
	Window find_menu_item_window(Point(w.x()+50, w.y()+50), 240, 120, "Find Menu Item Window"); 
	find_menu_item_window.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));

	In_box txtbox_name(Point(120,10), 100, 30, "Category Name:"); 
	Text txt_result(Point(5,105), ""); 
	Button button_find_cat_sales(Point(10, 50), 200, 30, "Find Sales!", find_category_sales_cb);  

	find_menu_item_window.attach(txtbox_name); 
	find_menu_item_window.attach(txt_result); 
	find_menu_item_window.attach(button_find_cat_sales); 

	wait_for_menu_bar_click(); 
	menu_click_enabled = true;
	while (menu_userdata != Close_about_box)
	{
		cout << "Act on userdata = " << menu_userdata << endl;
		if (menu_userdata == Find_category_sales) { 
			cout<<"Find Category Sales"<<endl;
			ostringstream oss; 
			oss << m.category_sales(txtbox_name.get_string()); 
			string result = oss.str(); 
			
			if (result == "-1") {
				txt_result.set_label("Menu item '"+ txtbox_name.get_string() + "' not found");
			}
			else if (result == "-2") {
				txt_result.set_label("Please input menu item name first");
			}
			else {
				txt_result.set_label("Total sales for " + txtbox_name.get_string() + " = $" + result);	
			}
		}
		wait_for_menu_bar_click(); 
		menu_click_enabled = true;
	} 

	find_menu_item_window.detach(txtbox_name); 
	find_menu_item_window.detach(txt_result); 
	find_menu_item_window.detach(button_find_cat_sales); 
	return;
	/*Window add(Point(sw.x()+100, sw.y()+100), 450, 300, "Category Sales");
	add.callback((Fl_Callback*)Menu_Bar_CB, Address (Close_about_box));
	Window_text_display t(Point(0,15),450, 285, "Category Sales", display_cb );
	string text = m.catsales();
	cout<<text<<endl;
	t.set_buffer(text.c_str());
	add.attach(t);
	wait_for_menu_bar_click();
	add.detach(t);*/
	
	
	
}
//show about box info window
void do_about_box(Window& w) //AJN B1
{
	Window ab(Point(w.x()+100, w.y()+100), 450, 300, "About Box");
	ab.color(Color::white);
	ab.callback((Fl_Callback*)Menu_Bar_CB, Address (Close_about_box));
	Image andre(Point(15,100),"andre.gif");
	Image fransiska(Point(315,100),"fransiska.gif");
	Image spencer(Point(165,100),"spencer.gif");
	Text msg1(Point(15,50),  "Andre Jean Nel");
	Text msg2(Point(15,75), "CSCE 121 SEC 200");
	Text msg3(Point(165,50), "Spenser Bennett Harden");
	Text msg4(Point(165,75),  "CSCE 121 SEC 200");
	Text msg5(Point(315,50), "Fransiska Putri Wina");
	Text msg6(Point(315,75), "IF4093");
	
	msg1.set_color(Color::black);
	msg2.set_color(Color::black);
	msg3.set_color(Color::black);
	msg4.set_color(Color::black);
	msg5.set_color(Color::black);
	msg6.set_color(Color::black);
	ab.attach(msg1);
	ab.attach(msg2);
	ab.attach(msg3);
	ab.attach(msg4);
	ab.attach(msg5);
	ab.attach(msg6);
	ab.attach(andre);
	ab.attach(fransiska);
	ab.attach(spencer);
	wait_for_menu_bar_click();
	ab.detach(msg1);//clean up window
	ab.detach(msg2);//clean up window
	ab.detach(msg3);//clean up window
	ab.detach(msg4);//clean up window
	ab.detach(msg5);//clean up window
	ab.detach(msg6);//clean up window
	ab.detach(andre);
	ab.detach(fransiska);
	ab.detach(spencer);
	
	return;
}

/* These following code written by Fransiska Putri Wina to solve B.3 */
void do_about_help_box(Window& w) 
{
	Window ab(Point(w.x()+100, w.y()+100), 550, 220, "Help Box");
	ab.color(Color::white);
	ab.callback((Fl_Callback*)Menu_Bar_CB, Address (Close_about_box));
	string help = "These are explanantion of the menu in ROMS aplication:";
	string help2 = "First, please perform Reads Orders, Recipe, and Menu Items.";
	string help3 = "Menu Show is used to show data that have been read previously.";
	string help3_2 = "The buttons (Recipes -- Order Items) will perform the same function as menu Show.";
	string help4 = "Menu Find is used to perform 'queries find' to the data.";
	string help5 = "Menu Update is used to modify the data from user input.";
	string help6 = "Menu About contain information regarding ROMS application.";
	string help7 = "Menu exit close the application and save changes the data.";
	Text msg(Point(15,30), help);
	Text msg2(Point(15,55), help2);
	Text msg3(Point(15,80), help3);
	Text msg4(Point(15,100), help3_2);
	Text msg5(Point(15,125), help4);
	Text msg6(Point(15,150), help5);
	Text msg7(Point(15,175), help6);
	Text msg8(Point(15,200), help7);
	msg.set_color(Color::black);
	msg2.set_color(Color::black);
	msg3.set_color(Color::black);
	msg4.set_color(Color::black);
	msg5.set_color(Color::black);
	msg6.set_color(Color::black);
	msg7.set_color(Color::black);
	msg8.set_color(Color::black);
	ab.attach(msg);
	ab.attach(msg2);
	ab.attach(msg3);
	ab.attach(msg4);
	ab.attach(msg5);
	ab.attach(msg6);
	ab.attach(msg7);
	ab.attach(msg8);
	wait_for_menu_bar_click();
	ab.detach(msg);//clean up window
	return;
}
/*end of code by FPW, B.3 */


void do_read(Window& w, ROMS_Menu& m, string dfn, string msg, Msg_type type)
{
	//Here again we linked our code directly to the FLTK library instead of creating an interface in our Graph_lib interface to FLTK
	//We did it for lack of time, which reflects the real word. Unfortunately if we wanted to move our code to a different graphics
	//library, we have to change our code and not just our Graphic_lib implementation. we are using the FLTK file chooser directly.
	Fl_File_Chooser fc(dfn.c_str(), "*.dat", Fl_File_Chooser::CREATE, msg.c_str());
	fc.show();
	while (fc.shown())
		Fl::wait();	//wait for OK or Cancel button
	if(0!=fc.value())//make sure there is a string to use as a filename
	{
		string fname = fc.value();
		switch(type) {
			case Read_recipes_ingredients:
				m.read_recipes_ingredients(fname);
				break;
			case Read_orders:
				m.Read_orders(fname);
				break;
			case Read_category_menu_items:
				m.read_catprds(fname);
				break;
			default:
				throw InvalidType();
		}
	}
	return;
}

/* These following code written by Fransiska Putri Wina to solve C - find sales for menu item */
void show_find_menu_item(Window& w,ROMS_Menu& m) 
{
	Window find_menu_item_window(Point(w.x()+50, w.y()+50), 240, 120, "Find Menu Item Window"); 
	find_menu_item_window.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));

	In_box txtbox_name(Point(120,10), 100, 30, "Menu Item Name:"); 
	Text txt_result(Point(5,105), ""); 
	Button button_find(Point(10, 50), 200, 30, "Find Sales!", find_menu_item_cb);  

	find_menu_item_window.attach(txtbox_name); 
	find_menu_item_window.attach(txt_result); 
	find_menu_item_window.attach(button_find); 

	wait_for_menu_bar_click(); 
	menu_click_enabled = true;
	while (menu_userdata != Close_about_box)
	{
		cout << "Act on userdata = " << menu_userdata << endl;
		if (menu_userdata == find_menu_item_button) { 
			ostringstream oss; 
			oss << m.find(3, txtbox_name.get_string()); 
			string result = oss.str(); 
			
			if (result == "-1") {
				txt_result.set_label("Menu item '"+ txtbox_name.get_string() + "' not found");
			}
			else if (result == "-2") {
				txt_result.set_label("Please input menu item name first");
			}
			else {
				txt_result.set_label("Total sales for " + txtbox_name.get_string() + " = $" + result);	
			}
		}
		wait_for_menu_bar_click(); 
		menu_click_enabled = true;
	} 

	find_menu_item_window.detach(txtbox_name); 
	find_menu_item_window.detach(txt_result); 
	find_menu_item_window.detach(button_find); 
	return;
}
/* End of code by FPW, C - find sales for menu item */

/*These following code written by Fransiska Putri Wina to Solve C - add recipes */
void update_recipe(Window& w, ROMS_Menu& m) 
{
	Window ab(Point(w.x()+100, w.y()+100), 300, 150, "Update Recipe Window"); 
	ab.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));

	In_box txtbox_chef_name(Point(85,10), 200, 30, "Chef Name:"); 
	In_box txtbox_instruction(Point(85,50), 200, 30, "Instruction:"); 
	Button button_add(Point(10, 90), 270, 30, "Add Recipe", update_recipe_cb); 
	Text txt_comment(Point(5,140), ""); 

	ab.attach(txtbox_chef_name); 
	ab.attach(txtbox_instruction); 
	ab.attach(txt_comment); 
	ab.attach(button_add); 
	
	wait_for_menu_bar_click(); 
	menu_click_enabled = true;
	while (menu_userdata != Close_about_box)
	{
		cout << "Act on userdata = " << menu_userdata << endl;
		if (menu_userdata == update_recipe_button) { 
			string inst = txtbox_instruction.get_string();
			int result = m.update_recipe(txtbox_chef_name.get_string(), inst);
			if (result == 1) {
				txt_comment.set_label("Recipe has been add successfully"); 
			}
			else {
				txt_comment.set_label("Adding recipe failed"); 
			}
		}
		wait_for_menu_bar_click(); 
		menu_click_enabled = true;
	} 

	ab.detach(txtbox_chef_name); 
	ab.detach(txtbox_instruction); 
	ab.detach(txt_comment); 
	ab.detach(button_add); 
	return;
}
/* End of code by FPW, C - add recipes */

//AJN D
void do_graph_order_sales(Window& w,ROMS_Menu& m)
{
	cout<<"do_graph_order_sales"<<endl;
	Window ab(Point(w.x()+100, w.y()+100), 700, 400, "Graph Order Sales");
	ab.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));
	ab.color(Color::black);
	// All Wrong Code, not right meaing of specifications
	vector<double> sales(m.get_month_order_sales());
	double max_sales = 0;
	for(int i =0;i<sales.size();i++)
	{
		if(sales[i]>max_sales)
			max_sales = sales[i];
		cout<<sales[i]<<endl;
		
	}
	int max = (int)ceil(max_sales);
	cout<<max<<endl;
	int notches = max/100+1;
	//for(int i =0;i<sales.size();i++)
	{
		//cout<<sales[i]<<endl;
		//cout<<(350/notches/100*sales[i])+1<<endl;
	}
	Axis xaxis(Axis::x,Point(50,375),600,12,"");
	Axis yaxis(Axis::y,Point(50,375),350,notches,"Sales[One notch = $100]");
	Text jan(Point(85,395),"JAN");
	Text feb(Point(135,395),"FEB");
	Text mar(Point(185,395),"MAR");
	Text apr(Point(235,395),"APR");
	Text may(Point(285,395),"MAY");
	Text jun(Point(335,395),"JUN");
	Text jul(Point(385,395),"JUL");
	Text aug(Point(435,395),"AUG");
	Text sep(Point(485,395),"SEP");
	Text oct(Point(535,395),"OCT");
	Text nov(Point(585,395),"NOV");
	Text dec(Point(635,395),"DEC");
	/*
	Text txt_100(Point(10,295),"$100");
	Text txt_200(Point(10,205),"$200");
	Text txt_300(Point(10,115),"$300");
	Text txt_400(Point(10,25),"$400");
	*/
	
	Rectangle jans(Point(50,25+(int)(350-350.0/notches/100*sales[0])),50,(int)(350.0/notches/100*sales[0])+1);
	Rectangle febs(Point(100,25+(int)(350-350.0/notches/100*sales[1])),50,(int)(350.0/notches/100*sales[1])+1);
	Rectangle mars(Point(150,25+(int)(350-350.0/notches/100*sales[2])),50,(int)(350.0/notches/100*sales[2])+1);
	Rectangle aprs(Point(200,25+(int)(350-350.0/notches/100*sales[3])),50,(int)(350.0/notches/100*sales[3])+1);
	Rectangle mays(Point(250,25+(int)(350-350.0/notches/100*sales[4])),50,(int)(350.0/notches/100*sales[4])+1);
	Rectangle juns(Point(300,25+(int)(350-350.0/notches/100*sales[5])),50,(int)(350.0/notches/100*sales[5])+1);
	Rectangle juls(Point(350,25+(int)(350-350.0/notches/100*sales[6])),50,(int)(350.0/notches/100*sales[6])+1);
	Rectangle augs(Point(400,25+(int)(350-350.0/notches/100*sales[7])),50,(int)(350.0/notches/100*sales[7])+1);
	Rectangle seps(Point(450,25+(int)(350-350.0/notches/100*sales[8])),50,(int)(350.0/notches/100*sales[8])+1);
	Rectangle octs(Point(500,25+(int)(350-350.0/notches/100*sales[9])),50,(int)(350.0/notches/100*sales[9])+1);
	Rectangle novs(Point(550,25+(int)(350-350.0/notches/100*sales[10])),50,(int)(350.0/notches/100*sales[10])+1); 
	Rectangle decs(Point(600,25+(int)(350-350.0/notches/100*sales[11])),50,(int)(350.0/notches/100*sales[11])+1);
	
	/*
	Open_polyline orders_sales;
	for (int i=0;i<=11;i++) {
		orders_sales.add(Point((i+1)*50+50,25+(int)(350-350.0/notches/100*sales[i])));
	}
	//orders_sales.color(Color::blue);*/

	
	jans.set_fill_color(Color::blue);
	febs.set_fill_color(Color::blue);
	mars.set_fill_color(Color::blue);
	aprs.set_fill_color(Color::blue);
	mays.set_fill_color(Color::blue);
	juns.set_fill_color(Color::blue);
	juls.set_fill_color(Color::blue);
	augs.set_fill_color(Color::blue);
	seps.set_fill_color(Color::blue);
	octs.set_fill_color(Color::blue);
	novs.set_fill_color(Color::blue);
	decs.set_fill_color(Color::blue);
	
	
	//ab.attach(orders_sales);
	
	ab.attach(jans);
	ab.attach(febs);
	ab.attach(mars);
	ab.attach(aprs);
	ab.attach(mays);
	ab.attach(juns);
	ab.attach(juls);
	ab.attach(augs);
	ab.attach(seps);
	ab.attach(octs);
	ab.attach(novs);
	ab.attach(decs);
	
	ab.attach(jan);
	ab.attach(feb);
	ab.attach(mar);
	ab.attach(apr);
	ab.attach(may);
	ab.attach(jun);
	ab.attach(jul);
	ab.attach(aug);
	ab.attach(sep);
	ab.attach(oct);
	ab.attach(nov);
	ab.attach(dec);
	/*
	ab.attach(txt_100);
	ab.attach(txt_200);
	ab.attach(txt_300);
	ab.attach(txt_400);
	*/
	ab.attach(xaxis);
	ab.attach(yaxis);
	
	
	wait_for_menu_bar_click();
	menu_click_enabled = true;
	
	ab.detach(xaxis);
	ab.detach(yaxis);
	ab.detach(jan);
	ab.detach(feb);
	ab.detach(mar);
	ab.detach(apr);
	ab.detach(may);
	ab.detach(jun);
	ab.detach(jul);
	ab.detach(aug);
	ab.detach(sep);
	ab.detach(oct);
	ab.detach(nov);
	ab.detach(dec);
	/*
	ab.detach(txt_100);
	ab.detach(txt_200);
	ab.detach(txt_300);
	ab.detach(txt_400);*/
	
	
	ab.detach(jans);
	ab.detach(febs);
	ab.detach(mars);
	ab.detach(aprs);
	ab.detach(mays);
	ab.detach(juns);
	ab.detach(juls);
	ab.detach(augs);
	ab.detach(seps);
	ab.detach(octs);
	ab.detach(novs);
	ab.detach(decs);
	//wait_for_menu_bar_click();
	return;
}
void do_graph_table_sales(Window& w,ROMS_Menu& m)
{
	cout<<"do_graph_table_sales"<<endl;
	Window ab(Point(w.x()+100, w.y()+100), 1500, 400, "Graph Order Sales");
	ab.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));
	ab.color(Color::black);
	map<int,double> tables = m.get_table_sales();
	typedef map<int,double>::const_iterator Iter;
	double max_sales = 0;
	for(Iter p =tables.begin();p!=tables.end();++p)
	{
		if(p->second>max_sales)
			max_sales = p->second;
		//cout<<p->first<<":"<<p->second<<endl;
	}
	int max = (int)ceil(max_sales);
	int notches = max/25+1;
	Vector_ref<Point> points(new Point(50,375));
	Vector_ref<Shape> labs(new Text(Point(0,0),""));
	int c = 0;
	int numtabs = tables.size();
	for(Iter p =tables.begin();p!=tables.end();++p)
	{
		ostringstream ss;
		ss<<p->first;
		labs.push_back(new Text(Point((int)(50+c*(1400-0)/numtabs),395),ss.str()));
		points.push_back(new Point((int)(60+c*(1400-0)/numtabs),(int)(350-350.0/notches/25*p->second)));
		c++;
	}
	Open_polyline table_sales;
	for (int i=0;i<points.size();i++) 
	{
		
		table_sales.add(points[i]);
		
	}
	
	Axis yaxis(Axis::y,Point(50,375),350,notches,"Sales[One notch = $25]");
	Axis xaxis(Axis::x,Point(50,375),1400,tables.size(),"");
	
	ab.attach(xaxis);
	ab.attach(yaxis);
	ab.attach(table_sales);
	for(int i =0;i<labs.size();i++)
	{
		ab.attach(labs[i]);
	}
	
	wait_for_menu_bar_click();
	menu_click_enabled = true;
	ab.detach(xaxis);
	ab.detach(yaxis);
	ab.detach(table_sales);
	for(int i =0;i<labs.size();i++)
	{
		ab.detach(labs[i]);
	}
	
	return;
}

/* These following code written by Fransiska Putri Wina to solve D - 3 */

void do_graph_category_sales(Window& w,ROMS_Menu& m)
{
	cout<<"do_graph_category_sales"<<endl;
	Window ab(Point(w.x()+100, w.y()+100), 800, 400, "Graph Category Sales");
	ab.callback((Fl_Callback*)Menu_Bar_2_CB, Address (Close_about_box));
	ab.color(Color::black);
	vector<vector<double> > cat_sales = m.get_categories_sales();
	vector<double> sales(m.get_month_order_sales());

	//bar graph

	// 0 - Appetizer
	// 1 - Entrees
	// 2 - Dessert
	// 3 - Drink
	vector<double> percent(4);

	//january
	if (sales[0] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[0][i]/sales[0];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle jans_0(Point(85,25),30,(int)(350*percent[0]+1));
	Rectangle jans_1(Point(85,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle jans_2(Point(85,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle jans_3(Point(85,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//february
	if (sales[1] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[1][i]/sales[1];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle febs_0(Point(135,25),30,(int)(350*percent[0]+1));
	Rectangle febs_1(Point(135,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle febs_2(Point(135,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle febs_3(Point(135,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//march
	if (sales[2] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[2][i]/sales[2];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle mars_0(Point(185,25),30,(int)(350*percent[0]+1));
	Rectangle mars_1(Point(185,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle mars_2(Point(185,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle mars_3(Point(185,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//april
	if (sales[3] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[3][i]/sales[3];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle aprs_0(Point(235,25),30,(int)(350*percent[0]+1));
	Rectangle aprs_1(Point(235,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle aprs_2(Point(235,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle aprs_3(Point(235,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//may
	if (sales[4] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[4][i]/sales[4];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle mays_0(Point(285,25),30,(int)(350*percent[0]+1));
	Rectangle mays_1(Point(285,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle mays_2(Point(285,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle mays_3(Point(285,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//june
	if (sales[5] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[5][i]/sales[5];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle juns_0(Point(335,25),30,(int)(350*percent[0]+1));
	Rectangle juns_1(Point(335,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle juns_2(Point(335,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle juns_3(Point(335,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//july
	if (sales[6] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[6][i]/sales[6];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle juls_0(Point(385,25),30,(int)(350*percent[0]+1));
	Rectangle juls_1(Point(385,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle juls_2(Point(385,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle juls_3(Point(385,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//august
	if (sales[7] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[7][i]/sales[7];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle augs_0(Point(435,25),30,(int)(350*percent[0]+1));
	Rectangle augs_1(Point(435,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle augs_2(Point(435,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle augs_3(Point(435,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//september
	if (sales[8] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[8][i]/sales[8];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle septs_0(Point(485,25),30,(int)(350*percent[0]+1));
	Rectangle septs_1(Point(485,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle septs_2(Point(485,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle septs_3(Point(485,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//october
	if (sales[9] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[9][i]/sales[9];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle octs_0(Point(535,25),30,(int)(350*percent[0]+1));
	Rectangle octs_1(Point(535,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle octs_2(Point(535,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle octs_3(Point(535,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//november
	if (sales[10] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[10][i]/sales[10];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle novs_0(Point(585,25),30,(int)(350*percent[0]+1));
	Rectangle novs_1(Point(585,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle novs_2(Point(585,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle novs_3(Point(585,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	//december
	if (sales[11] != 0) {
		for (int i = 0; i <4; i++) {
			cout << "tes";
			percent[i] = cat_sales[11][i]/sales[11];
			cout << percent [i]<<endl;
		}
	}
	else {
		for (int i = 0; i<4; i++) {
			percent[i] = 0;
		}
	}
	Rectangle decs_0(Point(635,25),30,(int)(350*percent[0]+1));
	Rectangle decs_1(Point(635,25+(int)(350*percent[0])),30,(int)(350*percent[1]+1));
	Rectangle decs_2(Point(635,25+(int)(350*(percent[0]+percent[1]))),30,(int)(350*percent[2]+1));
	Rectangle decs_3(Point(635,25+(int)(350*(percent[0]+percent[1]+percent[2]))),30,(int)(350*percent[3]+1));

	jans_0.set_fill_color(Color::red);
	febs_0.set_fill_color(Color::red);
	mars_0.set_fill_color(Color::red);
	aprs_0.set_fill_color(Color::red);
	mays_0.set_fill_color(Color::red);
	juns_0.set_fill_color(Color::red);
	juls_0.set_fill_color(Color::red);
	augs_0.set_fill_color(Color::red);
	septs_0.set_fill_color(Color::red);
	octs_0.set_fill_color(Color::red);
	novs_0.set_fill_color(Color::red);
	decs_0.set_fill_color(Color::red);
	jans_1.set_fill_color(Color::yellow);
	febs_1.set_fill_color(Color::yellow);
	mars_1.set_fill_color(Color::yellow);
	aprs_1.set_fill_color(Color::yellow);
	mays_1.set_fill_color(Color::yellow);
	juns_1.set_fill_color(Color::yellow);
	juls_1.set_fill_color(Color::yellow);
	augs_1.set_fill_color(Color::yellow);
	septs_1.set_fill_color(Color::yellow);
	octs_1.set_fill_color(Color::yellow);
	novs_1.set_fill_color(Color::yellow);
	decs_1.set_fill_color(Color::yellow);
	jans_2.set_fill_color(Color::green);
	febs_2.set_fill_color(Color::green);
	mars_2.set_fill_color(Color::green);
	aprs_2.set_fill_color(Color::green);
	mays_2.set_fill_color(Color::green);
	juns_2.set_fill_color(Color::green);
	juls_2.set_fill_color(Color::green);
	augs_2.set_fill_color(Color::green);
	septs_2.set_fill_color(Color::green);
	octs_2.set_fill_color(Color::green);
	novs_2.set_fill_color(Color::green);
	decs_2.set_fill_color(Color::green);
	jans_3.set_fill_color(Color::blue);
	febs_3.set_fill_color(Color::blue);
	mars_3.set_fill_color(Color::blue);
	aprs_3.set_fill_color(Color::blue);
	mays_3.set_fill_color(Color::blue);
	juns_3.set_fill_color(Color::blue);
	juls_3.set_fill_color(Color::blue);
	augs_3.set_fill_color(Color::blue);
	septs_3.set_fill_color(Color::blue);
	octs_3.set_fill_color(Color::blue);
	novs_3.set_fill_color(Color::blue);
	decs_3.set_fill_color(Color::blue);
	

	//axis
	Axis xaxis(Axis::x,Point(50,375),600,12,"");
	Axis yaxis(Axis::y,Point(50,375),350,10,"Sales");
	
	//legend
	Rectangle rec_app(Point(680,75),30,30); rec_app.set_fill_color(Color::red); Text txt_app(Point(715,90),"Appetizers"); 
	Rectangle rec_ent(Point(680,110),30,30); rec_ent.set_fill_color(Color::yellow); Text txt_ent(Point(715,125),"Entrees");
	Rectangle rec_des(Point(680,145),30,30); rec_des.set_fill_color(Color::green); Text txt_des(Point(715,160),"Desserts");
	Rectangle rec_drnk(Point(680,180),30,30); rec_drnk.set_fill_color(Color::blue); Text txt_drnk(Point(715,195),"Drinks");

	//label for xaxis
	Text jan(Point(85,395),"JAN");
	Text feb(Point(135,395),"FEB");
	Text mar(Point(185,395),"MAR");
	Text apr(Point(235,395),"APR");
	Text may(Point(285,395),"MAY");
	Text jun(Point(335,395),"JUN");
	Text jul(Point(385,395),"JUL");
	Text aug(Point(435,395),"AUG");
	Text sep(Point(485,395),"SEP");
	Text oct(Point(535,395),"OCT");
	Text nov(Point(585,395),"NOV");
	Text dec(Point(635,395),"DEC");
	//label for yaxis
	Text txt_10(Point(10,345),"10%");
	Text txt_20(Point(10,310),"20%");
	Text txt_30(Point(10,275),"30%");
	Text txt_40(Point(10,240),"40%");
	Text txt_50(Point(10,205),"50%");
	Text txt_60(Point(10,170),"60%");
	Text txt_70(Point(10,135),"70%");
	Text txt_80(Point(10,100),"80%");
	Text txt_90(Point(10,65),"90%");
	Text txt_100(Point(10,30),"100%");


	//attaching the component
	ab.attach(jans_0);ab.attach(jans_1);ab.attach(jans_2);ab.attach(jans_3);
	ab.attach(febs_0);ab.attach(febs_1);ab.attach(febs_2);ab.attach(febs_3);
	ab.attach(mars_0);ab.attach(mars_1);ab.attach(mars_2);ab.attach(mars_3);
	ab.attach(aprs_0);ab.attach(aprs_1);ab.attach(aprs_2);ab.attach(aprs_3);
	ab.attach(mays_0);ab.attach(mays_1);ab.attach(mays_2);ab.attach(mays_3);
	ab.attach(juns_0);ab.attach(juns_1);ab.attach(juns_2);ab.attach(juns_3);
	ab.attach(juls_0);ab.attach(juls_1);ab.attach(juls_2);ab.attach(juls_3);
	ab.attach(augs_0);ab.attach(augs_1);ab.attach(augs_2);ab.attach(augs_3);
	ab.attach(septs_0);ab.attach(septs_1);ab.attach(septs_2);ab.attach(septs_3);
	ab.attach(octs_0);ab.attach(octs_1);ab.attach(octs_2);ab.attach(octs_3);
	ab.attach(novs_0);ab.attach(novs_1);ab.attach(novs_2);ab.attach(novs_3);
	ab.attach(decs_0);ab.attach(decs_1);ab.attach(decs_2);ab.attach(decs_3);

	ab.attach(rec_app);ab.attach(txt_app);
	ab.attach(rec_ent);ab.attach(txt_ent);
	ab.attach(rec_des);ab.attach(txt_des);
	ab.attach(rec_drnk);ab.attach(txt_drnk);

	ab.attach(jan);
	ab.attach(feb);
	ab.attach(mar);
	ab.attach(apr);
	ab.attach(may);
	ab.attach(jun);
	ab.attach(jul);
	ab.attach(aug);
	ab.attach(sep);
	ab.attach(oct);
	ab.attach(nov);
	ab.attach(dec);

	ab.attach(txt_10);
	ab.attach(txt_20);
	ab.attach(txt_30);
	ab.attach(txt_40);
	ab.attach(txt_50);
	ab.attach(txt_60);
	ab.attach(txt_70);
	ab.attach(txt_80);
	ab.attach(txt_90);
	ab.attach(txt_100);

	ab.attach(xaxis);
	ab.attach(yaxis);
	
	
	wait_for_menu_bar_click();
	menu_click_enabled = true;
	
	ab.detach(xaxis);
	ab.detach(yaxis);
	ab.detach(rec_app);ab.detach(txt_app);
	ab.detach(rec_ent);ab.detach(txt_ent);
	ab.detach(rec_des);ab.detach(txt_des);
	ab.detach(rec_drnk);ab.detach(txt_drnk);
	ab.detach(jan);
	ab.detach(feb);
	ab.detach(mar);
	ab.detach(apr);
	ab.detach(may);
	ab.detach(jun);
	ab.detach(jul);
	ab.detach(aug);
	ab.detach(sep);
	ab.detach(oct);
	ab.detach(nov);
	ab.detach(dec);
	ab.detach(txt_10);
	ab.detach(txt_20);
	ab.detach(txt_30);
	ab.detach(txt_40);
	ab.detach(txt_50);
	ab.detach(txt_60);
	ab.detach(txt_70);
	ab.detach(txt_80);
	ab.detach(txt_90);
	ab.detach(txt_100);

	ab.detach(jans_0);ab.detach(jans_1);ab.detach(jans_2);ab.detach(jans_3);
	ab.detach(febs_0);ab.detach(febs_1);ab.detach(febs_2);ab.detach(febs_3);
	ab.detach(mars_0);ab.detach(mars_1);ab.detach(mars_2);ab.detach(mars_3);
	ab.detach(aprs_0);ab.detach(aprs_1);ab.detach(aprs_2);ab.detach(aprs_3);
	ab.detach(mays_0);ab.detach(mays_1);ab.detach(mays_2);ab.detach(mays_3);
	ab.detach(juns_0);ab.detach(juns_1);ab.detach(juns_2);ab.detach(juns_3);
	ab.detach(juls_0);ab.detach(juls_1);ab.detach(juls_2);ab.detach(juls_3);
	ab.detach(augs_0);ab.detach(augs_1);ab.detach(augs_2);ab.detach(augs_3);
	ab.detach(septs_0);ab.detach(septs_1);ab.detach(septs_2);ab.detach(septs_3);
	ab.detach(octs_0);ab.detach(octs_1);ab.detach(octs_2);ab.detach(octs_3);
	ab.detach(novs_0);ab.detach(novs_1);ab.detach(novs_2);ab.detach(novs_3);
	ab.detach(decs_0);ab.detach(decs_1);ab.detach(decs_2);ab.detach(decs_3);
	
	
	return;
}
/* end of code by FPW, D - 3 */
